package com.liwuji.liwujiredisdocker.controller;

import com.alibaba.fastjson2.JSON;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author liwuji
 * @date 2024/10/25
 * @desc
 **/
@RestController
@RequestMapping("redis")
public class HelloController {
    @Resource
    private RedisTemplate redisTemplate;
    @GetMapping("value")
    public String  getValue(String key){
        Object o = redisTemplate.opsForValue().get(key);
        if(o != null){
          return JSON.toJSONString(o);
        }
        return  "not exist key！";
    }
    @GetMapping("putValue")
    public String  putValue(String key,String value){
         redisTemplate.opsForValue().set(key,value);
         return "success";
    }

}
